<?php
 require_once("../inc/sku.php");
 
  //Confirms that the POST Exist and if it's going to create or update an entry
 if(isset($_POST['Sku_id']))
 {
	//Creates new Price
 	
 	print_r($_POST);
 	$results = addprice($_POST);
	
	if($results === true)
	{
		$cleaned_url = get_string_before($_SERVER['HTTP_REFERER'], "?");
		$cleaned_url .= "?id=".$_POST['Sku_id']."&newprice";
		header("location:$cleaned_url");
	}
	else
	{
		$price = html_input_treatment($_POST);
	}
		
	$type_update = "New Price";
 }
 //Creates a blank Price for creating a new Price entry
 else 
 {
 	$price = blank_price();
	
	$heading = "New";
	$type_update = "New Price";
 }
  
?>
<!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title><?=$title ?> <?=$type_update ?></title>
         <? require('../inc/header-info.php'); ?>
    </head>
    <body>
        <div class="container">
            <? include('../inc/nav.php'); ?>
         <form id="newPrice" method="post" action="addprice.php">
         	<h4>Enter <?=$heading ?> Price</h4>
            <div class="input-append">
            	<input type="hidden" name="Sku_id" value="<?=$_GET['id']?>">
            	
  				<input class="span2 required" id="appendedInputButtons" size="16" type="text" name="price" placeholder="Price" value="<?=$price['price']?>">
  				<button class="btn" type="submit"><?=$heading?></button>
  				<a class="btn" href="<?=$_SERVER['HTTP_REFERER']?>">Cancel</a>
			</div>
			</form>   
		</div>
		
	<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>	
	<script>
		$(function(){
			
			$("#newPrice").validate();
			
		});
		
		
	</script>
	</body>
</html>